package sk.xorty.channels;

import org.springframework.integration.Message;
import org.springframework.stereotype.Component;
import sk.xorty.domain.Account;

import java.util.Comparator;

/**
 * Can compare 2 messages with Account payload and therefore prioritize channel.
 */
@Component
public class AccountComparator implements Comparator<Message<Account>> {

    @Override
    public int compare(Message<Account> message1, Message<Account> message2) {
        Account acc1 = message1.getPayload();
        Account acc2 = message2.getPayload();

        Integer type1 = acc1.getAccountType();
        Integer type2 = acc2.getAccountType();

        return type1.compareTo(type2);
    }

}
